Skip to content

Add AsQobject trait #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

A trait which will wrap the QObjectExt methods for types which upcast to QObject. When used in conjunction with #1252 and #1226, this will allow any type that inherits from QObject - even if this is through many levels of inheritance - to have an as_qobject method, and if the trait is imported, expose the methods of QObject directly on that child class. Closes #562.

Copy link

codecov bot commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (723ba1e) to head (c3061e8).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1262   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines        12681     12681           
=========================================
  Hits         12681     12681           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BenFordTytherington BenFordTytherington force-pushed the add-qtobject-trait branch 2 times, most recently from 913c91b to 3f749ed Compare May 20, 2025 12:09
@BenFordTytherington BenFordTytherington requested review from LeonMatthesKDAB and ahayzen-kdab and removed request for jnbooth May 20, 2025 14:25
@LeonMatthesKDAB
Copy link
Collaborator

LeonMatthesKDAB commented May 20, 2025

@BenFordTytherington Didn't we at some point discuss just directly implementing QObjectExt for anything that is Upcast<QObject>, e.g.:

impl QObjectExt for T where T: Upcast<QObject> {
}

That way we don't need another trait 🤔

We should then however make sure to move all methods from QObject into QObjectExt (even dump_object_info)

@BenFordTytherington
Copy link
Collaborator Author

Just attempted to implement it for all these upcasting types for a bit, and the main problem is that now QObject upcasts to QObject, so we get a conflicting impl. I think this is initially why we went for a separate trait, and a blanket impl there, since my_obj.as_qobject().method() isn't too bad, compared to being able to do my_obj.method()

@LeonMatthesKDAB
Copy link
Collaborator

Why would we get a conflicting impl?
We no longer need to manually impl QObjectExt for QObject, as it will impl QObjectExt it via the auto-trait impl, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traits for CxxQtType/QtObject
3 participants